package com.example.xbrother.rule.battery;

import com.example.xbrother.rule.BaseBean;
import com.example.xbrother.rule.MaterialResult;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 电池空开类型-bean
 */
@Slf4j
public class BatteryAirSwitchTypeBean extends BaseBean {

    /**
     * 添加物料
     */
    public void add(BatteryAirSwitchTypeParam p, List<List<String>> list) {
        List<MaterialResult> r = p.getResult();
        // 所选UPS功率（功率模块*数量）/380/1.732*1.2=蓄电池空开大小
        double powerEach = (p.getTotalPower() * 1000) / 380 / 1.732 * 1.2;
        // 每节蓄电池的最小功率
        log.info("powerEach = {}", powerEach);
        // 比对，取最优解
        log.info("list = {}", list);
        int len = list.size();
        // 组成一个 数组，便于后续判断
        double[] powerList = new double[len];
        for (int i = 0; i < len; i++) {
            List<String> item = list.get(i);
            String powerStr = item.get(1);
            double powerItem = Double.parseDouble(powerStr);
            powerList[i] = powerItem;
        }
        log.info("powerList = {}", powerList);
        // 查找最接近的倍数值
        int[] rTemp = latestData(powerList, powerEach, 1);
        if (rTemp != null) {
            int index = rTemp[0];
            r.add(new MaterialResult(list.get(index).get(0), p.getGroupNum()));
        }
    }


}

